Skip to content

Commit fbd8047

Browse files
committed
[CGP] Drop poison-generating flags after hoisting
1 parent 1667095 commit fbd8047

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

llvm/lib/CodeGen/CodeGenPrepare.cpp

+6-2
Original file line numberDiff line numberDiff line change
@@ -8268,8 +8268,10 @@ static bool optimizeBranch(BranchInst *Branch, const TargetLowering &TLI,
82688268
if (CmpC.isPowerOf2() && Cmp->getPredicate() == ICmpInst::ICMP_ULT &&
82698269
match(UI, m_Shr(m_Specific(X), m_SpecificInt(CmpC.logBase2())))) {
82708270
IRBuilder<> Builder(Branch);
8271-
if (UI->getParent() != Branch->getParent())
8271+
if (UI->getParent() != Branch->getParent()) {
82728272
UI->moveBefore(Branch);
8273+
UI->dropPoisonGeneratingFlags();
8274+
}
82738275
Value *NewCmp = Builder.CreateCmp(ICmpInst::ICMP_EQ, UI,
82748276
ConstantInt::get(UI->getType(), 0));
82758277
LLVM_DEBUG(dbgs() << "Converting " << *Cmp << "\n");
@@ -8281,8 +8283,10 @@ static bool optimizeBranch(BranchInst *Branch, const TargetLowering &TLI,
82818283
(match(UI, m_Add(m_Specific(X), m_SpecificInt(-CmpC))) ||
82828284
match(UI, m_Sub(m_Specific(X), m_SpecificInt(CmpC))))) {
82838285
IRBuilder<> Builder(Branch);
8284-
if (UI->getParent() != Branch->getParent())
8286+
if (UI->getParent() != Branch->getParent()) {
82858287
UI->moveBefore(Branch);
8288+
UI->dropPoisonGeneratingFlags();
8289+
}
82868290
Value *NewCmp = Builder.CreateCmp(Cmp->getPredicate(), UI,
82878291
ConstantInt::get(UI->getType(), 0));
82888292
LLVM_DEBUG(dbgs() << "Converting " << *Cmp << "\n");

llvm/test/Transforms/CodeGenPrepare/RISCV/convert-to-eqz.ll

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ define i8 @hoist_add(i8 %x) {
55
; CHECK-LABEL: define i8 @hoist_add(
66
; CHECK-SAME: i8 [[X:%.*]]) {
77
; CHECK-NEXT: entry:
8-
; CHECK-NEXT: [[INC:%.*]] = add nuw nsw i8 [[X]], 1
8+
; CHECK-NEXT: [[INC:%.*]] = add i8 [[X]], 1
99
; CHECK-NEXT: [[TMP0:%.*]] = icmp eq i8 [[INC]], 0
1010
; CHECK-NEXT: br i1 [[TMP0]], label [[EXIT:%.*]], label [[IF_THEN:%.*]]
1111
; CHECK: if.then:
@@ -31,7 +31,7 @@ define i8 @hoist_lshr(i8 %x) {
3131
; CHECK-LABEL: define i8 @hoist_lshr(
3232
; CHECK-SAME: i8 [[X:%.*]]) {
3333
; CHECK-NEXT: entry:
34-
; CHECK-NEXT: [[INC:%.*]] = lshr exact i8 [[X]], 3
34+
; CHECK-NEXT: [[INC:%.*]] = lshr i8 [[X]], 3
3535
; CHECK-NEXT: [[TMP0:%.*]] = icmp eq i8 [[INC]], 0
3636
; CHECK-NEXT: br i1 [[TMP0]], label [[EXIT:%.*]], label [[IF_THEN:%.*]]
3737
; CHECK: if.then:

0 commit comments

Comments
 (0)