Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CGP] Drop poison-generating flags after hoisting #90382

Merged
merged 3 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions llvm/lib/CodeGen/CodeGenPrepare.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8270,6 +8270,7 @@ static bool optimizeBranch(BranchInst *Branch, const TargetLowering &TLI,
IRBuilder<> Builder(Branch);
if (UI->getParent() != Branch->getParent())
UI->moveBefore(Branch);
UI->dropPoisonGeneratingFlags();
Value *NewCmp = Builder.CreateCmp(ICmpInst::ICMP_EQ, UI,
ConstantInt::get(UI->getType(), 0));
LLVM_DEBUG(dbgs() << "Converting " << *Cmp << "\n");
Expand All @@ -8283,6 +8284,7 @@ static bool optimizeBranch(BranchInst *Branch, const TargetLowering &TLI,
IRBuilder<> Builder(Branch);
if (UI->getParent() != Branch->getParent())
UI->moveBefore(Branch);
UI->dropPoisonGeneratingFlags();
Value *NewCmp = Builder.CreateCmp(Cmp->getPredicate(), UI,
ConstantInt::get(UI->getType(), 0));
LLVM_DEBUG(dbgs() << "Converting " << *Cmp << "\n");
Expand Down
80 changes: 80 additions & 0 deletions llvm/test/Transforms/CodeGenPrepare/RISCV/convert-to-eqz.ll
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
}
Loading