1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-26 04:32:44 +01:00

[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
This commit is contained in:
Juneyoung Lee 2020-11-30 22:48:43 +09:00
parent c9317b869d
commit 26954b5028
2 changed files with 20 additions and 1 deletions

View File

@ -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

View File

@ -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
}