[llvm] r311626 - NewGVN: We weren't properly simplifying selects with equal arguments due to a thinko.
Daniel Berlin via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 23 19:43:18 PDT 2017
Author: dannyb
Date: Wed Aug 23 19:43:17 2017
New Revision: 311626
URL: http://llvm.org/viewvc/llvm-project?rev=311626&view=rev
Log:
NewGVN: We weren't properly simplifying selects with equal arguments due to a thinko.
Modified:
llvm/trunk/lib/Transforms/Scalar/NewGVN.cpp
llvm/trunk/test/Transforms/NewGVN/basic.ll
Modified: llvm/trunk/lib/Transforms/Scalar/NewGVN.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/NewGVN.cpp?rev=311626&r1=311625&r2=311626&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/NewGVN.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/NewGVN.cpp Wed Aug 23 19:43:17 2017
@@ -1025,7 +1025,7 @@ const Expression *NewGVN::createExpressi
return SimplifiedE;
} else if (isa<SelectInst>(I)) {
if (isa<Constant>(E->getOperand(0)) ||
- E->getOperand(0) == E->getOperand(1)) {
+ E->getOperand(1) == E->getOperand(2)) {
assert(E->getOperand(1)->getType() == I->getOperand(1)->getType() &&
E->getOperand(2)->getType() == I->getOperand(2)->getType());
Value *V = SimplifySelectInst(E->getOperand(0), E->getOperand(1),
Modified: llvm/trunk/test/Transforms/NewGVN/basic.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/NewGVN/basic.ll?rev=311626&r1=311625&r2=311626&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/NewGVN/basic.ll (original)
+++ llvm/trunk/test/Transforms/NewGVN/basic.ll Wed Aug 23 19:43:17 2017
@@ -1,17 +1,35 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt < %s -newgvn -S | FileCheck %s
define i32 @main() {
+; CHECK-LABEL: @main(
+; CHECK-NEXT: block1:
+; CHECK-NEXT: br label [[BLOCK2:%.*]]
+; CHECK: block2:
+; CHECK-NEXT: ret i32 0
+;
block1:
- %z1 = bitcast i32 0 to i32
- br label %block2
+ %z1 = bitcast i32 0 to i32
+ br label %block2
block2:
%z2 = bitcast i32 0 to i32
ret i32 %z2
}
-; CHECK: define i32 @main() {
-; CHECK-NEXT: block1:
-; CHECK-NEXT: br label %block2
-; CHECK: block2:
-; CHECK-NEXT: ret i32 0
-; CHECK-NEXT: }
+; Test that we simplify selects properly
+define i64 @simplifyselect(i64 %x, i64 %y, i1 %c1, i1 %c2, i1 %zzz) {
+; CHECK-LABEL: @simplifyselect(
+; CHECK-NEXT: [[SHARED:%.*]] = add i64 [[X:%.*]], [[Y:%.*]]
+; CHECK-NEXT: [[R1:%.*]] = select i1 [[C1:%.*]], i64 [[SHARED]], i64 [[X]]
+; CHECK-NEXT: [[R2:%.*]] = select i1 [[C2:%.*]], i64 [[SHARED]], i64 [[Y]]
+; CHECK-NEXT: [[R:%.*]] = add i64 [[R1]], [[R2]]
+; CHECK-NEXT: ret i64 [[R]]
+;
+ %shared = add i64 %x, %y
+ %r1 = select i1 %c1, i64 %shared, i64 %x
+ %r2 = select i1 %c2, i64 %shared, i64 %y
+ %tmp = select i1 %c2, i64 %x, i64 0
+ %r2_eq2 = select i1 %zzz, i64 %r2, i64 %r2
+ %r = add i64 %r1, %r2_eq2
+ ret i64 %r
+}
More information about the llvm-commits
mailing list