[PATCH] D54115: [InstCombine] do not shrink switch conditions to illegal types (PR29009)
Denis Bakhvalov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 5 10:58:58 PST 2018
dendibakh updated this revision to Diff 172617.
dendibakh added a comment.
Changed the comment.
Repository:
rL LLVM
https://reviews.llvm.org/D54115
Files:
lib/Transforms/InstCombine/InstructionCombining.cpp
test/Transforms/InstCombine/narrow-switch.ll
Index: test/Transforms/InstCombine/narrow-switch.ll
===================================================================
--- test/Transforms/InstCombine/narrow-switch.ll
+++ test/Transforms/InstCombine/narrow-switch.ll
@@ -105,10 +105,14 @@
define void @trunc64to59(i64 %a) {
; ALL-LABEL: @trunc64to59(
-; ALL: switch i59
-; ALL-NEXT: i59 0, label %sw.bb1
-; ALL-NEXT: i59 18717182647723699, label %sw.bb2
-; ALL-NEXT: ]
+; ALL-CHECK32: switch i59
+; ALL-CHECK32-NEXT: i59 0, label %sw.bb1
+; ALL-CHECK32-NEXT: i59 18717182647723699, label %sw.bb2
+; ALL-CHECK32-NEXT: ]
+; ALL-CHECK64: switch i64
+; ALL-CHECK64-NEXT: i64 0, label %sw.bb1
+; ALL-CHECK64-NEXT: i64 18717182647723699, label %sw.bb2
+; ALL-CHECK64-NEXT: ]
;
entry:
%tmp0 = and i64 %a, 15
@@ -206,3 +210,54 @@
ret i32 %rval
}
+; https://llvm.org/bugs/show_bug.cgi?id=29009
+
+ at a = global i32 0, align 4
+ at njob = global i32 0, align 4
+
+declare i32 @goo()
+
+; Make sure we do not shrink to illegal types (i3 in this case)
+; if original type is legal (i32 in this case)
+
+define void @PR29009() {
+; ALL-LABEL: @PR29009(
+; ALL: switch i32
+; ALL-NEXT: i32 0, label
+; ALL-NEXT: i32 3, label
+; ALL-NEXT: ]
+;
+ br label %1
+
+; <label>:1: ; preds = %10, %0
+ %2 = load volatile i32, i32* @njob, align 4
+ %3 = icmp ne i32 %2, 0
+ br i1 %3, label %4, label %11
+
+; <label>:4: ; preds = %1
+ %5 = call i32 @goo()
+ %6 = and i32 %5, 7
+ switch i32 %6, label %7 [
+ i32 0, label %8
+ i32 3, label %9
+ ]
+
+; <label>:7: ; preds = %4
+ store i32 6, i32* @a, align 4
+ br label %10
+
+; <label>:8: ; preds = %4
+ store i32 1, i32* @a, align 4
+ br label %10
+
+; <label>:9: ; preds = %4
+ store i32 2, i32* @a, align 4
+ br label %10
+
+; <label>:10: ; preds = %13, %12, %11, %10, %9, %8, %7
+ br label %1
+
+; <label>:11: ; preds = %1
+ ret void
+}
+
Index: lib/Transforms/InstCombine/InstructionCombining.cpp
===================================================================
--- lib/Transforms/InstCombine/InstructionCombining.cpp
+++ lib/Transforms/InstCombine/InstructionCombining.cpp
@@ -2482,9 +2482,10 @@
unsigned NewWidth = Known.getBitWidth() - std::max(LeadingKnownZeros, LeadingKnownOnes);
// Shrink the condition operand if the new type is smaller than the old type.
- // This may produce a non-standard type for the switch, but that's ok because
- // the backend should extend back to a legal type for the target.
- if (NewWidth > 0 && NewWidth < Known.getBitWidth()) {
+ // But do not shrink to a non-standard type, because backend can't generate
+ // good code for that yet.
+ if (NewWidth > 0 && NewWidth < Known.getBitWidth() &&
+ shouldChangeType(Known.getBitWidth(), NewWidth)) {
IntegerType *Ty = IntegerType::get(SI.getContext(), NewWidth);
Builder.SetInsertPoint(&SI);
Value *NewCond = Builder.CreateTrunc(Cond, Ty, "trunc");
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D54115.172617.patch
Type: text/x-patch
Size: 3208 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181105/da5511b2/attachment.bin>
More information about the llvm-commits
mailing list