[PATCH] D92270: [ConstantFold] Fold more operations to poison
Juneyoung Lee via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Nov 30 05:17:29 PST 2020
aqjune added a comment.
Hi,
It seems it is related to two optimizations:
(1) `select i1 x, true, y` -> `or i1 x, y`
(2) `or i1 x, poison` -> `poison`
Semantically, the first one is broken. It needs to freeze y. But, it will introduce a lot of freeze instructions. The clang patches that introduce noundef to function arguments is still ongoing.
Another workaround is to weaken (2) to `or i1 x, poison` -> `x`. This fixes the miscompilation; I'll push a commit that does this.
--- a/llvm/lib/IR/ConstantFold.cpp
+++ b/llvm/lib/IR/ConstantFold.cpp
@@ -1105,7 +1105,10 @@ Constant *llvm::ConstantFoldBinaryInstruction(unsigned Opcode, Constant *C1,
}
// Binary operations propagate poison.
- if (isa<PoisonValue>(C1) || isa<PoisonValue>(C2))
+ bool PoisonFold = !C1->getType()->isIntegerTy(1) ||
+ (Opcode != Instruction::Or && Opcode != Instruction::And &&
+ Opcode != Instruction::Xor);
+ if (PoisonFold && (isa<PoisonValue>(C1) || isa<PoisonValue>(C2)))
return PoisonValue::get(C1->getType());
// Handle scalar UndefValue and scalable vector UndefValue. Fixed-length
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D92270/new/
https://reviews.llvm.org/D92270
More information about the cfe-commits
mailing list