[llvm] cc78189 - [InstCombine] Prevent complexity commutation in dec_mask_commute_neg_i32

Simon Pilgrim via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 24 06:38:50 PDT 2022


Author: Simon Pilgrim
Date: 2022-08-24T14:35:04+01:00
New Revision: cc7818939c3f4e1156cbaef1400756a563c580f8

URL: https://github.com/llvm/llvm-project/commit/cc7818939c3f4e1156cbaef1400756a563c580f8
DIFF: https://github.com/llvm/llvm-project/commit/cc7818939c3f4e1156cbaef1400756a563c580f8.diff

LOG: [InstCombine] Prevent complexity commutation in dec_mask_commute_neg_i32

Noticed by @spatel in D110488

Added: 
    

Modified: 
    llvm/test/Transforms/InstCombine/add-mask-neg.ll

Removed: 
    


################################################################################
diff  --git a/llvm/test/Transforms/InstCombine/add-mask-neg.ll b/llvm/test/Transforms/InstCombine/add-mask-neg.ll
index 7a7d4216e3bd..0fe1b743d7fd 100644
--- a/llvm/test/Transforms/InstCombine/add-mask-neg.ll
+++ b/llvm/test/Transforms/InstCombine/add-mask-neg.ll
@@ -18,13 +18,15 @@ define i32 @dec_mask_neg_i32(i32 %X) {
   ret i32 %dec
 }
 
-define i32 @dec_mask_commute_neg_i32(i32 %X) {
+define i32 @dec_mask_commute_neg_i32(i32 %A) {
 ; CHECK-LABEL: @dec_mask_commute_neg_i32(
-; CHECK-NEXT:    [[NEG:%.*]] = sub i32 0, [[X:%.*]]
-; CHECK-NEXT:    [[MASK:%.*]] = and i32 [[NEG]], [[X]]
+; CHECK-NEXT:    [[X:%.*]] = sdiv i32 42, [[A:%.*]]
+; CHECK-NEXT:    [[NEG:%.*]] = sub nsw i32 0, [[X]]
+; CHECK-NEXT:    [[MASK:%.*]] = and i32 [[X]], [[NEG]]
 ; CHECK-NEXT:    [[DEC:%.*]] = add i32 [[MASK]], -1
 ; CHECK-NEXT:    ret i32 [[DEC]]
 ;
+  %X = sdiv i32 42, %A ; thwart complexity-based canonicalization
   %neg = sub i32 0, %X
   %mask = and i32 %X, %neg
   %dec = add i32 %mask, -1


        


More information about the llvm-commits mailing list