Author: Juneyoung Lee Date: 2020-11-30T22:58:31+09:00 New Revision: 9c49dcc356eb4c59fc1353bbbaae6d3a56a656c1
URL: https://github.com/llvm/llvm-project/commit/9c49dcc356eb4c59fc1353bbbaae6d3a56a656c1 DIFF: https://github.com/llvm/llvm-project/commit/9c49dcc356eb4c59fc1353bbbaae6d3a56a656c1.diff LOG: [ConstantFold] Don't fold and/or i1 poison to poison (NFC) .. because it causes miscompilation when combined with select i1 -> and/or. It is the select fold which is incorrect; but it is costly to disable the fold, so hack this one. D92270 Added: Modified: llvm/lib/IR/ConstantFold.cpp llvm/test/Transforms/InstSimplify/ConstProp/poison.ll Removed: ################################################################################ diff --git a/llvm/lib/IR/ConstantFold.cpp b/llvm/lib/IR/ConstantFold.cpp index 3243ddd604ee..d9564a31b5de 100644 --- a/llvm/lib/IR/ConstantFold.cpp +++ b/llvm/lib/IR/ConstantFold.cpp @@ -1105,7 +1105,14 @@ Constant *llvm::ConstantFoldBinaryInstruction(unsigned Opcode, Constant *C1, } // Binary operations propagate poison. - if (isa<PoisonValue>(C1) || isa<PoisonValue>(C2)) + // FIXME: Currently, or/and i1 poison aren't folded into poison because + // it causes miscompilation when combined with another optimization in + // InstCombine (select i1 -> and/or). The select fold is wrong, but + // fixing it requires an effort, so temporarily disable this until it is + // fixed. + bool PoisonFold = !C1->getType()->isIntegerTy(1) || + (Opcode != Instruction::Or && Opcode != Instruction::And); + if (PoisonFold && (isa<PoisonValue>(C1) || isa<PoisonValue>(C2))) return PoisonValue::get(C1->getType()); // Handle scalar UndefValue and scalable vector UndefValue. Fixed-length diff --git a/llvm/test/Transforms/InstSimplify/ConstProp/poison.ll b/llvm/test/Transforms/InstSimplify/ConstProp/poison.ll index 542823a44e2f..f3fe29ff57ba 100644 --- a/llvm/test/Transforms/InstSimplify/ConstProp/poison.ll +++ b/llvm/test/Transforms/InstSimplify/ConstProp/poison.ll @@ -114,3 +114,15 @@ define void @other_ops(i8 %x) { call void (...) @use(i1 %i1, i1 %i2, i8 %i3, i8 %i4, i8* getelementptr (i8, i8* poison, i64 1), i8* getelementptr inbounds (i8, i8* undef, i64 1)) ret void } + +; TODO: these must be folded into poison; D92270 +define void @logicalops_i1(i1 %x) { +; CHECK-LABEL: @logicalops_i1( +; CHECK-NEXT: call void (...) @use(i1 true, i1 false) +; CHECK-NEXT: ret void +; + %i1 = or i1 %x, poison + %i2 = and i1 %x, poison + call void (...) @use(i1 %i1, i1 %i2) + ret void +} _______________________________________________ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits