[llvm] r265805 - [InstCombine] Fix miscompile in FoldSPFofSPF
David Majnemer via llvm-commits
llvm-commits at lists.llvm.org
Fri Apr 8 09:51:49 PDT 2016
Author: majnemer
Date: Fri Apr 8 11:51:49 2016
New Revision: 265805
URL: http://llvm.org/viewvc/llvm-project?rev=265805&view=rev
Log:
[InstCombine] Fix miscompile in FoldSPFofSPF
We had a select of a cast of a select but attempted to replace the outer
select with the inner select dispite their incompatible types.
Patch by Anton Korobeynikov!
This fixes PR27236.
Added:
llvm/trunk/test/Transforms/InstCombine/pr27236.ll
Modified:
llvm/trunk/lib/Transforms/InstCombine/InstCombineSelect.cpp
Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineSelect.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineSelect.cpp?rev=265805&r1=265804&r2=265805&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineSelect.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineSelect.cpp Fri Apr 8 11:51:49 2016
@@ -642,6 +642,9 @@ Instruction *InstCombiner::FoldSPFofSPF(
Value *A, Value *B,
Instruction &Outer,
SelectPatternFlavor SPF2, Value *C) {
+ if (Outer.getType() != Inner->getType())
+ return nullptr;
+
if (C == A || C == B) {
// MAX(MAX(A, B), B) -> MAX(A, B)
// MIN(MIN(a, b), a) -> MIN(a, b)
Added: llvm/trunk/test/Transforms/InstCombine/pr27236.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/pr27236.ll?rev=265805&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/pr27236.ll (added)
+++ llvm/trunk/test/Transforms/InstCombine/pr27236.ll Fri Apr 8 11:51:49 2016
@@ -0,0 +1,19 @@
+; RUN: opt -S -instcombine < %s | FileCheck %s
+
+define float @test1(i32 %scale) {
+entry:
+ %tmp1 = icmp sgt i32 1, %scale
+ %tmp2 = select i1 %tmp1, i32 1, i32 %scale
+ %tmp3 = sitofp i32 %tmp2 to float
+ %tmp4 = icmp sgt i32 %tmp2, 0
+ %sel = select i1 %tmp4, float %tmp3, float 0.000000e+00
+ ret float %sel
+}
+
+; CHECK-LABEL: define float @test1(
+; CHECK: %[[tmp1:.*]] = icmp slt i32 %scale, 1
+; CHECK: %[[tmp2:.*]] = select i1 %[[tmp1]], i32 1, i32 %scale
+; CHECK: %[[tmp3:.*]] = sitofp i32 %[[tmp2]] to float
+; CHECK: %[[tmp4:.*]] = icmp sgt i32 %[[tmp2]], 0
+; CHECK: %[[sel:.*]] = select i1 %[[tmp4]], float %[[tmp3]], float 0.000000e+00
+; CHECK: ret float %[[sel]]
More information about the llvm-commits
mailing list