diff options
author | Nikita Popov <npopov@redhat.com> | 2024-06-04 15:45:32 +0200 |
---|---|---|
committer | Nikita Popov <npopov@redhat.com> | 2024-06-04 15:48:08 +0200 |
commit | 3cd67eeca28ab1084d02b7976de1af4c4c8d37d5 (patch) | |
tree | 3b055996e3c115713bc8d023c5c151b7d294b5e3 /llvm/lib | |
parent | 11725b5240840e077c944af6a56e75dd00275395 (diff) | |
download | llvm-3cd67eeca28ab1084d02b7976de1af4c4c8d37d5.zip llvm-3cd67eeca28ab1084d02b7976de1af4c4c8d37d5.tar.gz llvm-3cd67eeca28ab1084d02b7976de1af4c4c8d37d5.tar.bz2 |
[InstCombine] Drop range attr in select of ctz fold
The range may no longer be valid after the select has been
optimized away.
This fixes the kernel miscompiles reported at
https://github.com/ClangBuiltLinux/linux/issues/2031.
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp index a3ddb40..a9aba55 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp @@ -1127,7 +1127,7 @@ static Instruction *foldSelectCtlzToCttz(ICmpInst *ICI, Value *TrueVal, /// into: /// %0 = tail call i32 @llvm.cttz.i32(i32 %x, i1 false) static Value *foldSelectCttzCtlz(ICmpInst *ICI, Value *TrueVal, Value *FalseVal, - InstCombiner::BuilderTy &Builder) { + InstCombinerImpl &IC) { ICmpInst::Predicate Pred = ICI->getPredicate(); Value *CmpLHS = ICI->getOperand(0); Value *CmpRHS = ICI->getOperand(1); @@ -1169,6 +1169,9 @@ static Value *foldSelectCttzCtlz(ICmpInst *ICI, Value *TrueVal, Value *FalseVal, // Explicitly clear the 'is_zero_poison' flag. It's always valid to go from // true to false on this flag, so we can replace it for all users. II->setArgOperand(1, ConstantInt::getFalse(II->getContext())); + // A range annotation on the intrinsic may no longer be valid. + II->dropPoisonGeneratingAnnotations(); + IC.addToWorklist(II); return SelectArg; } @@ -1921,7 +1924,7 @@ Instruction *InstCombinerImpl::foldSelectInstWithICmp(SelectInst &SI, if (Value *V = foldSelectICmpLshrAshr(ICI, TrueVal, FalseVal, Builder)) return replaceInstUsesWith(SI, V); - if (Value *V = foldSelectCttzCtlz(ICI, TrueVal, FalseVal, Builder)) + if (Value *V = foldSelectCttzCtlz(ICI, TrueVal, FalseVal, *this)) return replaceInstUsesWith(SI, V); if (Value *V = canonicalizeSaturatedSubtract(ICI, TrueVal, FalseVal, Builder)) |