[PATCH] D25955: [InstCombine] Ensure that truncated int types are legal.
bryant via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 25 11:38:20 PDT 2016
bryant created this revision.
bryant added a reviewer: spatel.
bryant added a subscriber: llvm-commits.
bryant set the repository for this revision to rL LLVM.
Fixes the FIXMEs in https://reviews.llvm.org/D25952 and https://reviews.llvm.org/rL285075.
Repository:
rL LLVM
https://reviews.llvm.org/D25955
Files:
lib/Transforms/InstCombine/InstCombineCompares.cpp
test/Transforms/InstCombine/icmp-shl-zext-simplify.ll
test/Transforms/InstCombine/icmp.ll
Index: test/Transforms/InstCombine/icmp.ll
===================================================================
--- test/Transforms/InstCombine/icmp.ll
+++ test/Transforms/InstCombine/icmp.ll
@@ -1208,12 +1208,10 @@
ret i1 %cmp
}
-; FIXME: We shouldn't be creating illegal types like i15 in InstCombine.
-
define i1 @icmp_shl17(i32 %x) {
; CHECK-LABEL: @icmp_shl17(
-; CHECK-NEXT: [[TMP1:%.*]] = trunc i32 %x to i15
-; CHECK-NEXT: [[CMP:%.*]] = icmp slt i15 [[TMP1]], 18
+; CHECK-NEXT: [[SHL:%.*]] = shl i32 %x, 17
+; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[SHL]], 2359296
; CHECK-NEXT: ret i1 [[CMP]]
;
%shl = shl i32 %x, 17
Index: test/Transforms/InstCombine/icmp-shl-zext-simplify.ll
===================================================================
--- test/Transforms/InstCombine/icmp-shl-zext-simplify.ll
+++ test/Transforms/InstCombine/icmp-shl-zext-simplify.ll
@@ -14,8 +14,8 @@
define i1 @icmp_ule_64(i128) {
; CHECK-LABEL: @icmp_ule_64(
-; CHECK-NEXT: [[TMP2:%.*]] = trunc i128 %0 to i64
-; CHECK-NEXT: [[D:%.*]] = icmp eq i64 [[TMP2]], 0
+; CHECK-NEXT: [[C:%.*]] = shl nuw i128 %0, 64
+; CHECK-NEXT: [[D:%.*]] = icmp ult i128 [[C]], 18446744073709551616
; CHECK-NEXT: ret i1 [[D]]
;
%c = shl nuw i128 %0, 64
@@ -34,11 +34,10 @@
ret i1 %d
}
-; FIXME: InstCombine ought not to emit the potentially illegal i48.
define <2 x i1> @icmp_ule_16x2(<2 x i64>) {
; CHECK-LABEL: @icmp_ule_16x2(
-; CHECK-NEXT: [[TMP2:%.*]] = trunc <2 x i64> %0 to <2 x i48>
-; CHECK-NEXT: [[D:%.*]] = icmp eq <2 x i48> [[TMP2]], zeroinitializer
+; CHECK-NEXT: [[C:%.*]] = shl nuw <2 x i64> %0, <i64 16, i64 16>
+; CHECK-NEXT: [[D:%.*]] = icmp ult <2 x i64> [[C]], <i64 65536, i64 65536>
; CHECK-NEXT: ret <2 x i1> [[D]]
;
%c = shl nuw <2 x i64> %0, <i64 16, i64 16>
Index: lib/Transforms/InstCombine/InstCombineCompares.cpp
===================================================================
--- lib/Transforms/InstCombine/InstCombineCompares.cpp
+++ lib/Transforms/InstCombine/InstCombineCompares.cpp
@@ -1950,17 +1950,15 @@
And, Constant::getNullValue(And->getType()));
}
- // FIXME: This transform can create illegal types. Use the DataLayout to
- // decide when to try this?
-
// Transform (icmp pred iM (shl iM %v, N), C)
// -> (icmp pred i(M-N) (trunc %v iM to i(M-N)), (trunc (C>>N))
// Transform the shl to a trunc if (trunc (C>>N)) has no loss and M-N.
// This enables us to get rid of the shift in favor of a trunc which can be
// free on the target. It has the additional benefit of comparing to a
// smaller constant, which will be target friendly.
unsigned Amt = ShiftAmt->getLimitedValue(TypeBits - 1);
- if (Shl->hasOneUse() && Amt != 0 && C->countTrailingZeros() >= Amt) {
+ if (Shl->hasOneUse() && Amt != 0 && C->countTrailingZeros() >= Amt &&
+ DL.isLegalInteger(TypeBits - Amt)) {
Type *TruncTy = IntegerType::get(Cmp.getContext(), TypeBits - Amt);
if (X->getType()->isVectorTy())
TruncTy = VectorType::get(TruncTy, X->getType()->getVectorNumElements());
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D25955.75748.patch
Type: text/x-patch
Size: 3116 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161025/09220dbd/attachment.bin>
More information about the llvm-commits
mailing list