Skip to content

Commit

Permalink
support multiple phis and undef
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbaden committed Dec 3, 2024
1 parent f1a6029 commit 7ff052b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
6 changes: 3 additions & 3 deletions test/LLVMIR/freeze-masked-div-rem.ll
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ if.end:
; CHECK: [[F0:%.*]] = freeze i8 %yy
; CHECK-NEXT: %z = sdiv i8 %x, [[F0:%.*]]
%z = sdiv i8 %x, %yy
br i1 %cmp, label %if2.then, label %if2.end
br i1 %cmp, label %if2.then, label %if2.end

if2.then:
store i8 %z, ptr %v, align 8
Expand Down Expand Up @@ -46,12 +46,12 @@ if.end:
; CHECK: [[F1:%.*]] = freeze i8 %bb
; CHECK-NEXT: %zz = sdiv i8 %x, [[F1:%.*]]
%zz = sdiv i8 %x, %bb
br i1 %cmp, label %if2.then, label %if2.end
br i1 %cmp, label %if2.then, label %if2.end

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

if2.end:
ret void
}
}
12 changes: 4 additions & 8 deletions third_party/intel/lib/LLVMIR/LLVMIRFreezeMaskedDivRem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

using namespace llvm;

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

for (BasicBlock &BB : F) {
for (Instruction &I : BB) {
if (PHINode *PhiNode = dyn_cast<PHINode>(&I)) {
Changed |= processBasicBlock(BB, PhiNode);
continue;
}
break;
for (PHINode &PhiNode : BB.phis()) {
Changed |= processPhiNode(BB, &PhiNode);
}
}

Expand Down

0 comments on commit 7ff052b

Please sign in to comment.