[llvm] r319818 - [SystemZ] Validate shifted compare value in adjustForTestUnderMask
Ulrich Weigand via llvm-commits
llvm-commits at lists.llvm.org
Tue Dec 5 11:42:07 PST 2017
Author: uweigand
Date: Tue Dec 5 11:42:07 2017
New Revision: 319818
URL: http://llvm.org/viewvc/llvm-project?rev=319818&view=rev
Log:
[SystemZ] Validate shifted compare value in adjustForTestUnderMask
When folding a shift into a test-under-mask comparison, make sure that
there is no loss of precision when creating the shifted comparison
value. This usually never happens, except for certain always-true
comparisons in unoptimized code.
Fixes PR35529.
Modified:
llvm/trunk/lib/Target/SystemZ/SystemZISelLowering.cpp
llvm/trunk/test/CodeGen/SystemZ/int-cmp-47.ll
Modified: llvm/trunk/lib/Target/SystemZ/SystemZISelLowering.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/SystemZ/SystemZISelLowering.cpp?rev=319818&r1=319817&r2=319818&view=diff
==============================================================================
--- llvm/trunk/lib/Target/SystemZ/SystemZISelLowering.cpp (original)
+++ llvm/trunk/lib/Target/SystemZ/SystemZISelLowering.cpp Tue Dec 5 11:42:07 2017
@@ -2201,6 +2201,7 @@ static void adjustForTestUnderMask(Selec
NewC.Op0.getOpcode() == ISD::SHL &&
isSimpleShift(NewC.Op0, ShiftVal) &&
(MaskVal >> ShiftVal != 0) &&
+ ((CmpVal >> ShiftVal) << ShiftVal) == CmpVal &&
(NewCCMask = getTestUnderMaskCond(BitSize, NewC.CCMask,
MaskVal >> ShiftVal,
CmpVal >> ShiftVal,
@@ -2211,6 +2212,7 @@ static void adjustForTestUnderMask(Selec
NewC.Op0.getOpcode() == ISD::SRL &&
isSimpleShift(NewC.Op0, ShiftVal) &&
(MaskVal << ShiftVal != 0) &&
+ ((CmpVal << ShiftVal) >> ShiftVal) == CmpVal &&
(NewCCMask = getTestUnderMaskCond(BitSize, NewC.CCMask,
MaskVal << ShiftVal,
CmpVal << ShiftVal,
Modified: llvm/trunk/test/CodeGen/SystemZ/int-cmp-47.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/SystemZ/int-cmp-47.ll?rev=319818&r1=319817&r2=319818&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/SystemZ/int-cmp-47.ll (original)
+++ llvm/trunk/test/CodeGen/SystemZ/int-cmp-47.ll Tue Dec 5 11:42:07 2017
@@ -342,3 +342,25 @@ store:
exit:
ret void
}
+
+; Check that we don't fold a shift if the comparison value
+; would need to be shifted out of range
+define void @f19(i64 %a) {
+; CHECK-LABEL: f19:
+; CHECK-NOT: tmhh
+; CHECK: srlg [[REG:%r[0-5]]], %r2, 63
+; CHECK: cgibl [[REG]], 3, 0(%r14)
+; CHECK: br %r14
+entry:
+ %shr = lshr i64 %a, 63
+ %cmp = icmp ult i64 %shr, 3
+ br i1 %cmp, label %exit, label %store
+
+store:
+ store i32 1, i32 *@g
+ br label %exit
+
+exit:
+ ret void
+}
+
More information about the llvm-commits
mailing list