Skip to content

Commit 4de0c45

Browse files
committed
support multiple phis and undef
1 parent a1f110e commit 4de0c45

File tree

2 files changed

+7
-11
lines changed

2 files changed

+7
-11
lines changed

test/LLVMIR/freeze-masked-div-rem.ll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ if.end:
1515
; CHECK: [[F0:%.*]] = freeze i8 %yy
1616
; CHECK-NEXT: %z = sdiv i8 %x, [[F0:%.*]]
1717
%z = sdiv i8 %x, %yy
18-
br i1 %cmp, label %if2.then, label %if2.end
18+
br i1 %cmp, label %if2.then, label %if2.end
1919

2020
if2.then:
2121
store i8 %z, ptr %v, align 8
@@ -46,12 +46,12 @@ if.end:
4646
; CHECK: [[F1:%.*]] = freeze i8 %bb
4747
; CHECK-NEXT: %zz = sdiv i8 %x, [[F1:%.*]]
4848
%zz = sdiv i8 %x, %bb
49-
br i1 %cmp, label %if2.then, label %if2.end
49+
br i1 %cmp, label %if2.then, label %if2.end
5050

5151
if2.then:
5252
store i8 %z, ptr %v, align 8
5353
br label %if2.end
5454

5555
if2.end:
5656
ret void
57-
}
57+
}

third_party/intel/lib/LLVMIR/LLVMIRFreezeMaskedDivRem.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66

77
using namespace llvm;
88

9-
static bool processBasicBlock(BasicBlock &BB, PHINode *PhiNode) {
9+
static bool processPhiNode(BasicBlock &BB, PHINode *PhiNode) {
1010
if (!any_of(PhiNode->incoming_values(), [](Use &U) {
1111
Constant *C = dyn_cast<Constant>(&U);
12-
return C && C->isNullValue();
12+
return isa<UndefValue>(U) || C && C->isNullValue();
1313
})) {
1414
return false;
1515
}
@@ -34,12 +34,8 @@ static bool runOnFunction(Function &F) {
3434
bool Changed = false;
3535

3636
for (BasicBlock &BB : F) {
37-
for (Instruction &I : BB) {
38-
if (PHINode *PhiNode = dyn_cast<PHINode>(&I)) {
39-
Changed |= processBasicBlock(BB, PhiNode);
40-
continue;
41-
}
42-
break;
37+
for (PHINode &PhiNode : BB.phis()) {
38+
Changed |= processPhiNode(BB, &PhiNode);
4339
}
4440
}
4541

0 commit comments

Comments
 (0)