forked from llvm/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CGP] Drop poison-generating flags after hoisting (llvm#90382)
See the following case: ``` define i8 @SRC1(i8 %x) { entry: %cmp = icmp eq i8 %x, -1 br i1 %cmp, label %exit, label %if.then if.then: %inc = add nuw nsw i8 %x, 1 br label %exit exit: %retval = phi i8 [ %inc, %if.then ], [ -1, %entry ] ret i8 %retval } define i8 @tgt1(i8 %x) { entry: %inc = add nuw nsw i8 %x, 1 %0 = icmp eq i8 %inc, 0 br i1 %0, label %exit, label %if.then if.then: ; preds = %entry br label %exit exit: ; preds = %if.then, %entry %retval = phi i8 [ %inc, %if.then ], [ -1, %entry ] ret i8 %retval } ``` `optimizeBranch` converts `icmp eq X, -1` into cmp to zero on RISC-V and hoists the add into the entry block. Poison-generating flags should be dropped as they don't still hold. Proof: https://alive2.llvm.org/ce/z/sP7mvK Fixes llvm#90380
- Loading branch information
Showing
3 changed files
with
105 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
llvm/test/Transforms/CodeGenPrepare/RISCV/convert-to-eqz.ll
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 4 | ||
; RUN: opt -codegenprepare -S -mtriple=riscv64 < %s | FileCheck %s | ||
|
||
define i8 @hoist_add(i8 %x) { | ||
; CHECK-LABEL: define i8 @hoist_add( | ||
; CHECK-SAME: i8 [[X:%.*]]) { | ||
; CHECK-NEXT: entry: | ||
; CHECK-NEXT: [[INC:%.*]] = add i8 [[X]], 1 | ||
; CHECK-NEXT: [[TMP0:%.*]] = icmp eq i8 [[INC]], 0 | ||
; CHECK-NEXT: br i1 [[TMP0]], label [[EXIT:%.*]], label [[IF_THEN:%.*]] | ||
; CHECK: if.then: | ||
; CHECK-NEXT: br label [[EXIT]] | ||
; CHECK: exit: | ||
; CHECK-NEXT: [[RETVAL:%.*]] = phi i8 [ [[INC]], [[IF_THEN]] ], [ -1, [[ENTRY:%.*]] ] | ||
; CHECK-NEXT: ret i8 [[RETVAL]] | ||
; | ||
entry: | ||
%cmp = icmp eq i8 %x, -1 | ||
br i1 %cmp, label %exit, label %if.then | ||
|
||
if.then: | ||
%inc = add nuw nsw i8 %x, 1 | ||
br label %exit | ||
|
||
exit: | ||
%retval = phi i8 [ %inc, %if.then ], [ -1, %entry ] | ||
ret i8 %retval | ||
} | ||
|
||
define i8 @hoist_lshr(i8 %x) { | ||
; CHECK-LABEL: define i8 @hoist_lshr( | ||
; CHECK-SAME: i8 [[X:%.*]]) { | ||
; CHECK-NEXT: entry: | ||
; CHECK-NEXT: [[INC:%.*]] = lshr i8 [[X]], 3 | ||
; CHECK-NEXT: [[TMP0:%.*]] = icmp eq i8 [[INC]], 0 | ||
; CHECK-NEXT: br i1 [[TMP0]], label [[EXIT:%.*]], label [[IF_THEN:%.*]] | ||
; CHECK: if.then: | ||
; CHECK-NEXT: br label [[EXIT]] | ||
; CHECK: exit: | ||
; CHECK-NEXT: [[RETVAL:%.*]] = phi i8 [ [[INC]], [[IF_THEN]] ], [ -1, [[ENTRY:%.*]] ] | ||
; CHECK-NEXT: ret i8 [[RETVAL]] | ||
; | ||
entry: | ||
%cmp = icmp ult i8 %x, 8 | ||
br i1 %cmp, label %exit, label %if.then | ||
|
||
if.then: | ||
%inc = lshr exact i8 %x, 3 | ||
br label %exit | ||
|
||
exit: | ||
%retval = phi i8 [ %inc, %if.then ], [ -1, %entry ] | ||
ret i8 %retval | ||
} | ||
|
||
define i8 @nomove_add(i8 %x) { | ||
; CHECK-LABEL: define i8 @nomove_add( | ||
; CHECK-SAME: i8 [[X:%.*]]) { | ||
; CHECK-NEXT: entry: | ||
; CHECK-NEXT: [[INC:%.*]] = add i8 [[X]], 1 | ||
; CHECK-NEXT: [[TMP0:%.*]] = icmp eq i8 [[INC]], 0 | ||
; CHECK-NEXT: br i1 [[TMP0]], label [[EXIT:%.*]], label [[IF_THEN:%.*]] | ||
; CHECK: if.then: | ||
; CHECK-NEXT: br label [[EXIT]] | ||
; CHECK: exit: | ||
; CHECK-NEXT: [[RETVAL:%.*]] = phi i8 [ [[INC]], [[IF_THEN]] ], [ -1, [[ENTRY:%.*]] ] | ||
; CHECK-NEXT: ret i8 [[RETVAL]] | ||
; | ||
entry: | ||
%inc = add nuw nsw i8 %x, 1 | ||
%cmp = icmp eq i8 %x, -1 | ||
br i1 %cmp, label %exit, label %if.then | ||
|
||
if.then: | ||
br label %exit | ||
|
||
exit: | ||
%retval = phi i8 [ %inc, %if.then ], [ -1, %entry ] | ||
ret i8 %retval | ||
} |