[PATCH] D85687: [Instcombine] Fix uses of undef (PR46940)
Kazu Hirata via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 11 13:54:11 PDT 2020
kazu updated this revision to Diff 284884.
kazu added a comment.
I've rebased this patch on top of https://reviews.llvm.org/D85684.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D85687/new/
https://reviews.llvm.org/D85687
Files:
llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
llvm/test/Transforms/InstCombine/dont-distribute-phi.ll
Index: llvm/test/Transforms/InstCombine/dont-distribute-phi.ll
===================================================================
--- /dev/null
+++ llvm/test/Transforms/InstCombine/dont-distribute-phi.ll
@@ -0,0 +1,33 @@
+; RUN: opt < %s -instcombine -S | FileCheck %s
+;
+; This test ensures that InstCombine does not distribute And over Xor
+; using simplifications involving undef.
+
+define zeroext i1 @foo(i32 %arg) {
+; CHECK-LABEL: @foo(
+
+entry:
+ %cmp1 = icmp eq i32 %arg, 37
+ br i1 %cmp1, label %bb_then, label %bb_else
+
+bb_then:
+ call void @bar()
+ br label %bb_exit
+
+bb_else:
+ %cmp2 = icmp slt i32 %arg, 17
+ br label %bb_exit
+
+; CHECK: bb_exit:
+; CHECK-NEXT: %phi1 = phi i1 [ %cmp2, %bb_else ], [ undef, %bb_then ]
+; CHECK-NEXT: %xor1 = xor i1 %cmp1, true
+; CHECK-NEXT: %and1 = and i1 %phi1, %xor1
+; CHECK-NEXT: ret i1 %and1
+bb_exit:
+ %phi1 = phi i1 [ %cmp2, %bb_else ], [ undef, %bb_then ]
+ %xor1 = xor i1 %cmp1, true
+ %and1 = and i1 %phi1, %xor1
+ ret i1 %and1
+}
+
+declare void @bar()
Index: llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
===================================================================
--- llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
+++ llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
@@ -740,8 +740,10 @@
Value *A = Op0->getOperand(0), *B = Op0->getOperand(1), *C = RHS;
Instruction::BinaryOps InnerOpcode = Op0->getOpcode(); // op'
- Value *L = SimplifyBinOp(TopLevelOpcode, A, C, SQ.getWithInstruction(&I));
- Value *R = SimplifyBinOp(TopLevelOpcode, B, C, SQ.getWithInstruction(&I));
+ // Disable the use of undef because it's not safe to distribute undef.
+ auto SQDistributive = SQ.getWithInstruction(&I).getWithoutUndef();
+ Value *L = SimplifyBinOp(TopLevelOpcode, A, C, SQDistributive);
+ Value *R = SimplifyBinOp(TopLevelOpcode, B, C, SQDistributive);
// Do "A op C" and "B op C" both simplify?
if (L && R) {
@@ -777,8 +779,10 @@
Value *A = LHS, *B = Op1->getOperand(0), *C = Op1->getOperand(1);
Instruction::BinaryOps InnerOpcode = Op1->getOpcode(); // op'
- Value *L = SimplifyBinOp(TopLevelOpcode, A, B, SQ.getWithInstruction(&I));
- Value *R = SimplifyBinOp(TopLevelOpcode, A, C, SQ.getWithInstruction(&I));
+ // Disable the use of undef because it's not safe to distribute undef.
+ auto SQDistributive = SQ.getWithInstruction(&I).getWithoutUndef();
+ Value *L = SimplifyBinOp(TopLevelOpcode, A, B, SQDistributive);
+ Value *R = SimplifyBinOp(TopLevelOpcode, A, C, SQDistributive);
// Do "A op B" and "A op C" both simplify?
if (L && R) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D85687.284884.patch
Type: text/x-patch
Size: 2650 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200811/cc35549b/attachment.bin>
More information about the llvm-commits
mailing list