@@ -2049,3 +2049,94 @@ define i32 @zext_negpow2_use(i8 %x) {
2049
2049
%r = mul i32 %zx , -16777216 ; -1 << 24
2050
2050
ret i32 %r
2051
2051
}
2052
+
2053
+ define i32 @mul_sext_icmp_with_zero (i32 %x ) {
2054
+ ; CHECK-LABEL: @mul_sext_icmp_with_zero(
2055
+ ; CHECK-NEXT: ret i32 0
2056
+ ;
2057
+ %cmp = icmp eq i32 %x , 0
2058
+ %sext = sext i1 %cmp to i32
2059
+ %mul = mul i32 %sext , %x
2060
+ ret i32 %mul
2061
+ }
2062
+
2063
+ define i32 @test_mul_sext_bool (i1 %x , i32 %y ) {
2064
+ ; CHECK-LABEL: @test_mul_sext_bool(
2065
+ ; CHECK-NEXT: [[Y_NEG:%.*]] = sub i32 0, [[Y:%.*]]
2066
+ ; CHECK-NEXT: [[MUL:%.*]] = select i1 [[X:%.*]], i32 [[Y_NEG]], i32 0
2067
+ ; CHECK-NEXT: ret i32 [[MUL]]
2068
+ ;
2069
+ %sext = sext i1 %x to i32
2070
+ %mul = mul i32 %sext , %y
2071
+ ret i32 %mul
2072
+ }
2073
+
2074
+ define i32 @test_mul_sext_bool_nuw (i1 %x , i32 %y ) {
2075
+ ; CHECK-LABEL: @test_mul_sext_bool_nuw(
2076
+ ; CHECK-NEXT: [[Y_NEG:%.*]] = sub i32 0, [[Y:%.*]]
2077
+ ; CHECK-NEXT: [[MUL:%.*]] = select i1 [[X:%.*]], i32 [[Y_NEG]], i32 0
2078
+ ; CHECK-NEXT: ret i32 [[MUL]]
2079
+ ;
2080
+ %sext = sext i1 %x to i32
2081
+ %mul = mul nuw i32 %sext , %y
2082
+ ret i32 %mul
2083
+ }
2084
+
2085
+ define i32 @test_mul_sext_bool_nsw (i1 %x , i32 %y ) {
2086
+ ; CHECK-LABEL: @test_mul_sext_bool_nsw(
2087
+ ; CHECK-NEXT: [[Y_NEG:%.*]] = sub nsw i32 0, [[Y:%.*]]
2088
+ ; CHECK-NEXT: [[MUL:%.*]] = select i1 [[X:%.*]], i32 [[Y_NEG]], i32 0
2089
+ ; CHECK-NEXT: ret i32 [[MUL]]
2090
+ ;
2091
+ %sext = sext i1 %x to i32
2092
+ %mul = mul nsw i32 %sext , %y
2093
+ ret i32 %mul
2094
+ }
2095
+
2096
+ define i32 @test_mul_sext_bool_nuw_nsw (i1 %x , i32 %y ) {
2097
+ ; CHECK-LABEL: @test_mul_sext_bool_nuw_nsw(
2098
+ ; CHECK-NEXT: [[Y_NEG:%.*]] = sub nsw i32 0, [[Y:%.*]]
2099
+ ; CHECK-NEXT: [[MUL:%.*]] = select i1 [[X:%.*]], i32 [[Y_NEG]], i32 0
2100
+ ; CHECK-NEXT: ret i32 [[MUL]]
2101
+ ;
2102
+ %sext = sext i1 %x to i32
2103
+ %mul = mul nuw nsw i32 %sext , %y
2104
+ ret i32 %mul
2105
+ }
2106
+
2107
+ define i32 @test_mul_sext_bool_commuted (i1 %x , i32 %y ) {
2108
+ ; CHECK-LABEL: @test_mul_sext_bool_commuted(
2109
+ ; CHECK-NEXT: [[TMP1:%.*]] = xor i32 [[Y:%.*]], -2
2110
+ ; CHECK-NEXT: [[YY_NEG1:%.*]] = add i32 [[TMP1]], 1
2111
+ ; CHECK-NEXT: [[MUL:%.*]] = select i1 [[X:%.*]], i32 [[YY_NEG1]], i32 0
2112
+ ; CHECK-NEXT: ret i32 [[MUL]]
2113
+ ;
2114
+ %yy = xor i32 %y , 1
2115
+ %sext = sext i1 %x to i32
2116
+ %mul = mul i32 %yy , %sext
2117
+ ret i32 %mul
2118
+ }
2119
+
2120
+ define i32 @test_mul_sext_nonbool (i2 %x , i32 %y ) {
2121
+ ; CHECK-LABEL: @test_mul_sext_nonbool(
2122
+ ; CHECK-NEXT: [[SEXT:%.*]] = sext i2 [[X:%.*]] to i32
2123
+ ; CHECK-NEXT: [[MUL:%.*]] = mul i32 [[SEXT]], [[Y:%.*]]
2124
+ ; CHECK-NEXT: ret i32 [[MUL]]
2125
+ ;
2126
+ %sext = sext i2 %x to i32
2127
+ %mul = mul i32 %sext , %y
2128
+ ret i32 %mul
2129
+ }
2130
+
2131
+ define i32 @test_mul_sext_multiuse (i1 %x , i32 %y ) {
2132
+ ; CHECK-LABEL: @test_mul_sext_multiuse(
2133
+ ; CHECK-NEXT: [[SEXT:%.*]] = sext i1 [[X:%.*]] to i32
2134
+ ; CHECK-NEXT: tail call void @use(i32 [[SEXT]])
2135
+ ; CHECK-NEXT: [[MUL:%.*]] = mul i32 [[SEXT]], [[Y:%.*]]
2136
+ ; CHECK-NEXT: ret i32 [[MUL]]
2137
+ ;
2138
+ %sext = sext i1 %x to i32
2139
+ tail call void @use (i32 %sext )
2140
+ %mul = mul i32 %sext , %y
2141
+ ret i32 %mul
2142
+ }
0 commit comments