[llvm] [InstCombine] Fold `(trunc X)` into `X & Mask` inside `decomposeBitTestICmp` (PR #171195)
Tirthankar Mazumder via llvm-commits
llvm-commits at lists.llvm.org
Sat Dec 13 09:35:34 PST 2025
================
@@ -314,15 +314,10 @@ define i1 @sgt_n1_use(i32 %x) {
}
define i1 @trunc_eq_i32_i8(i32 %x) {
-; DL64-LABEL: @trunc_eq_i32_i8(
-; DL64-NEXT: [[TMP1:%.*]] = and i32 [[X:%.*]], 255
-; DL64-NEXT: [[R:%.*]] = icmp eq i32 [[TMP1]], 42
-; DL64-NEXT: ret i1 [[R]]
-;
-; DL8-LABEL: @trunc_eq_i32_i8(
-; DL8-NEXT: [[T:%.*]] = trunc i32 [[X:%.*]] to i8
-; DL8-NEXT: [[R:%.*]] = icmp eq i8 [[T]], 42
-; DL8-NEXT: ret i1 [[R]]
+; CHECK-LABEL: @trunc_eq_i32_i8(
----------------
wermos wrote:
Why exactly is `shouldChangeType` needed? IIUC, `trunc` requires the destination type to be smaller than the source type, otherwise the IR is ill-formed [according to the LangRef](https://llvm.org/docs/LangRef.html#id243).
In any case, in the other places in the file, like [here](https://github.com/llvm/llvm-project/blob/f721a3965caec0a57f1ad3e6e7b2628d2c8a5fa8/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp#L1453) and [here](https://github.com/llvm/llvm-project/blob/f721a3965caec0a57f1ad3e6e7b2628d2c8a5fa8/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp#L1491) they put the `DstBits` parameter first followed by `SrcBits`, even though the function signature is [`FromWidth` first and then `ToWidth` second](https://github.com/llvm/llvm-project/blob/f721a3965caec0a57f1ad3e6e7b2628d2c8a5fa8/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp#L313-L314).
I've made the change you requested, but I don't entirely understand why this guard is needed, and whether I made a mistake or I have the order of the function parameters correct.
https://github.com/llvm/llvm-project/pull/171195
More information about the llvm-commits
mailing list