Skip to content

Commit

Permalink
[CGP] Drop poison-generating flags after hoisting
Browse files Browse the repository at this point in the history
  • Loading branch information
dtcxzyw committed Apr 28, 2024
1 parent 1667095 commit fbd8047
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
8 changes: 6 additions & 2 deletions llvm/lib/CodeGen/CodeGenPrepare.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8268,8 +8268,10 @@ static bool optimizeBranch(BranchInst *Branch, const TargetLowering &TLI,
if (CmpC.isPowerOf2() && Cmp->getPredicate() == ICmpInst::ICMP_ULT &&
match(UI, m_Shr(m_Specific(X), m_SpecificInt(CmpC.logBase2())))) {
IRBuilder<> Builder(Branch);
if (UI->getParent() != Branch->getParent())
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 @@ -8281,8 +8283,10 @@ static bool optimizeBranch(BranchInst *Branch, const TargetLowering &TLI,
(match(UI, m_Add(m_Specific(X), m_SpecificInt(-CmpC))) ||
match(UI, m_Sub(m_Specific(X), m_SpecificInt(CmpC))))) {
IRBuilder<> Builder(Branch);
if (UI->getParent() != Branch->getParent())
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
4 changes: 2 additions & 2 deletions llvm/test/Transforms/CodeGenPrepare/RISCV/convert-to-eqz.ll
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ define i8 @hoist_add(i8 %x) {
; CHECK-LABEL: define i8 @hoist_add(
; CHECK-SAME: i8 [[X:%.*]]) {
; CHECK-NEXT: entry:
; CHECK-NEXT: [[INC:%.*]] = add nuw nsw i8 [[X]], 1
; 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:
Expand All @@ -31,7 +31,7 @@ define i8 @hoist_lshr(i8 %x) {
; CHECK-LABEL: define i8 @hoist_lshr(
; CHECK-SAME: i8 [[X:%.*]]) {
; CHECK-NEXT: entry:
; CHECK-NEXT: [[INC:%.*]] = lshr exact i8 [[X]], 3
; 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:
Expand Down

0 comments on commit fbd8047

Please sign in to comment.