It is clear that a PHI is a non-zero if all incoming values are non-zero constants.
Diff Detail
Event Timeline
Minor comments inline.
lib/Analysis/ValueTracking.cpp | ||
---|---|---|
2065 | A cleaner way of writing this would be: // llvm::all_of from STLExtras.h bool AllNonZeroConstants = all_of(PN->operands(), [](Value *V) { return isa<ConstantInt>(V) && !cast<ConstantInt>(V)->isZeroValue(); }); if (AllNonZeroConstants) return true; | |
test/Transforms/InstCombine/phi.ll | ||
768 | Minor: you can simplify the branch to br i1 %c, label %if.then, label %if.else. | |
774 | Minor: I'd add a call to an unknown function in one of the if branches. Without it simplifycfg changes the PHI to a select (and elides the control flow), after which LLVM is able to optimize this function in -O3, but with a call void @foo() in one of the branches, the phi->select conversion does not happen, and this test case demonstrates a truly missed optimization in LLVM today. |
A cleaner way of writing this would be: